/*    */ package com.zimbra.qa.unittest;
/*    */ 
/*    */ import com.zimbra.cs.mailbox.Mailbox;
/*    */ import com.zimbra.cs.mime.Mime.FixedMimeMessage;
/*    */ import com.zimbra.cs.mime.ParsedMessage;
/*    */ import com.zimbra.cs.store.Blob;
/*    */ import com.zimbra.cs.store.MailboxBlob;
/*    */ import com.zimbra.cs.store.StagedBlob;
/*    */ import com.zimbra.cs.store.StoreManager;
/*    */ import com.zimbra.cs.util.JMSession;
/*    */ import javax.mail.internet.MimeMessage;
/*    */ import junit.framework.TestCase;
/*    */ import org.apache.commons.lang.RandomStringUtils;
/*    */ import org.junit.Assert;
/*    */ import org.junit.Test;
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ public class TestStoreManager
/*    */   extends TestCase
/*    */ {
/*    */   private static final String USER_NAME = "user1";
/*    */   
/*    */   public static ParsedMessage getMessage()
/*    */     throws Exception
/*    */   {
/* 42 */     MimeMessage mm = new Mime.FixedMimeMessage(JMSession.getSession());
/* 43 */     mm.setHeader("From", " Jimi <jimi@example.com>");
/* 44 */     mm.setHeader("To", " Janis <janis@example.com>");
/* 45 */     mm.setHeader("Subject", "Hello");
/* 46 */     mm.setHeader("Message-ID", "<sakfuslkdhflskjch@oiwm.example.com>");
/* 47 */     mm.setText("nothing to see here" + RandomStringUtils.random(1024));
/* 48 */     return new ParsedMessage(mm, false);
/*    */   }
/*    */   
/*    */   @Test
/*    */   public void testStore() throws Exception {
/* 53 */     ParsedMessage pm = getMessage();
/* 54 */     byte[] mimeBytes = TestUtil.readInputStream(pm.getRawInputStream());
/*    */     
/* 56 */     Mailbox mbox = TestUtil.getMailbox("user1");
/*    */     
/* 58 */     StoreManager sm = StoreManager.getInstance();
/* 59 */     Blob blob = sm.storeIncoming(pm.getRawInputStream());
/*    */     
/* 61 */     Assert.assertEquals("blob size = message size", pm.getRawData().length, blob.getRawSize());
/* 62 */     Assert.assertTrue("blob content = mime content", TestUtil.bytesEqual(mimeBytes, blob.getInputStream()));
/*    */     
/* 64 */     StagedBlob staged = sm.stage(blob, mbox);
/* 65 */     Assert.assertEquals("staged size = blob size", blob.getRawSize(), staged.getSize());
/*    */     
/* 67 */     MailboxBlob mblob = sm.link(staged, mbox, 0, 0);
/* 68 */     Assert.assertEquals("link size = staged size", staged.getSize(), mblob.getSize());
/* 69 */     Assert.assertTrue("link content = mime content", TestUtil.bytesEqual(mimeBytes, mblob.getLocalBlob().getInputStream()));
/*    */     
/* 71 */     mblob = sm.getMailboxBlob(mbox, 0, 0, staged.getLocator());
/* 72 */     Assert.assertEquals("mblob size = staged size", staged.getSize(), mblob.getSize());
/* 73 */     Assert.assertTrue("mailboxblob content = mime content", TestUtil.bytesEqual(mimeBytes, mblob.getLocalBlob().getInputStream()));
/*    */   }
/*    */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/qa/unittest/TestStoreManager.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */